programming4us
           
 
 
Programming

Coding JavaScript for Mobile Browsers (part 3) - Writing to the document

- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Malwarebytes Premium 3.7.1 Serial Keys (LifeTime) 2019
12/25/2010 3:25:03 PM
2.3. Writing to the document

The document.write function allows us to dynamically write HTML code to a document while it is rendering. This was a very common technique in the ’90s, but there are a lot of reasons for not using it in modern websites. Today, the preferred technique is to manipulate the document using DOM after the onload event.


Note:

If your script doesn’t use document.write, you should use the script attribute defer="defer". This will tell compatible browsers that they shouldn’t wait for the script to download and/or execute to continue rendering the document.


That said, in the mobile space sometimes it is better not to deal with DOM (especially in low-end devices), so performing document.write operations can avoid a lot of problems. As Table 5 shows, this technique still works on a lot of browsers.

Table 5. document.write compatibility table
Browser/platformdocument.write support
SafariYes
Android browserYes
Symbian/S60Yes
Nokia Series 40Before 6th edition, no after onload support
webOSYes
BlackBerryBefore 4.6, no after onload support
NetFrontYes
Internet ExplorerYes
Motorola Internet BrowserYes, no after onload support
Opera MobileYes
Opera MiniServer rendering

For example, you can create a year selection list dynamically to save bytes in the original document. For rendering performance purposes, it is better to use document.write with all the HTML at the same time (including the beginning, contents, and end of a tag) rather than partially writing a tag with many lines. The following code demonstrates this technique:

<!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.0//EN"
"http://www.wapforum.org/DTD/xhtml-mobile10.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Document Write</title>
<script type="text/javascript">
function createNumericSelect(name, from, to) {
var html = "<select name='" + name + "'>";
for (var i=from; i<to; i++) {
html += "<option>" + i + "</option>";
}
html += "</select>";
document.write(html);
}
</script>

</head>

<body>
<form action="send">
<script type="text/javascript">
createNumericSelect('year', 1990, 2020);
</script>
</form>
</body>
</html>


Remember that document.write should not be used in an event handler, like onload or onclick, because it will have unpleasant results. If you need to dynamically generate content on the page, it is better to use DOM than document.write.

Other -----------------
- Programming the Mobile Web : JavaScript Mobile - Supported Technologies
- Security in Cloud Computing (part 4) - Audit and Compliance
- Security in Cloud Computing (part 3)
- Security in Cloud Computing (part 2) - Identity and Access Management
- Security in Cloud Computing (part 1) - Data Security and Storage
- Cloud Security and Privacy : Analyst Predictions
- CSS for Mobile Browsers : WebKit Extensions (part 2) - Border Image
- CSS for Mobile Browsers : WebKit Extensions (part 1) - Text Stroke and Fill
- jQuery 1.3 : Working with numeric form data (part 9) - The finished code
- jQuery 1.3 : Working with numeric form data (part 8) - Editing shipping information
- jQuery 1.3 : Working with numeric form data (part 7) - Deleting items
- jQuery 1.3 : Working with numeric form data (part 6) - Finishing touches
- jQuery 1.3 : Working with numeric form data (part 5)
- jQuery 1.3 : Working with numeric form data (part 4) - Dealing with decimal places
- jQuery 1.3 : Working with numeric form data (part 3) - Parsing and formatting currency
- jQuery 1.3 : Working with numeric form data (part 2)
- jQuery 1.3 : Working with numeric form data (part 1) - Shopping cart table structure
- The Art of SEO : Controlling Content with Cookies and Session IDs
- iPad SDK : New Graphics Functionality - We Are All Tool Users (part 5) - The Freehand Tool
- iPad SDK : New Graphics Functionality - We Are All Tool Users (part 4) - The Ellipse and Rectangle Tools
 
 
 
Top 10
 
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
- Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
- Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
- First look: Apple Watch

- 3 Tips for Maintaining Your Cell Phone Battery (part 1)

- 3 Tips for Maintaining Your Cell Phone Battery (part 2)
programming4us programming4us